// 函数预定义
function sum(x, y){
  return x + y
}

let sum1 = function(x, y){
  return x + y
}

// 左边 参数 右边函数体
let sum2 = (x,y) => {
  return x + y
}

console.log(sum2(4,5))

// 平方
let x = x => x*x
console.log(x(8))

// 点击按钮
let oBtn = document.querySelector('#btn')
console.log(oBtn)
oBtn.addEventListener('click', function(){
  // es5 call apply bind 改变this指向
  setTimeout(function(){
    console.log(this)
  }.bind(this), 1000)

  setTimeout(() =>{
    console.log(this)
  },2000)
  console.log(this)
})

// ES5 类
function People(name, age){
  this.name = name
  this.age = age
}
let p1 = new People('aqie',12)
console.log(p1)

/**
 * 箭头函数 不能作为构造函数
 */
let People2 = (name, age)=>{
  this.name = name
  this.age = age
}
let p2 = new People2('aqie',12)
console.log(p2)

/**
 * 箭头函数没有 arguments
 */
let foo = (...args) => {
  console.log(arguments)
  console.log(args)
}
foo(1,2,3)